import java.util.ArrayList;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: jack_yang
 * @Date: 2024/4/22
 * @Description: addition and subtraction
 */
public class Exercise {
    private int count = 50;
    private ArrayList<Equation> equationList;
    public Exercise(){
        equationList = new ArrayList<>();
    }

    public Exercise(int count){
        this.count = count;
        equationList = new ArrayList<>();
    }

    //判断算式是否已经在习题集中出现
    public boolean isExist(Equation paramEquation){
        return equationList.contains(paramEquation);
    }

    //产生纯加法习题方法

    public void generateAddExercise(){
        int i = 0;
        while(i<count){
            Equation equation = new Equation().generateAddEquation();
            if(isExist(equation)){
                continue;
            }else{
                equationList.add(equation);
                i++;
            }
        }
    }

    public void generateSubExercise(){
        int i = 0;
        while(i<count){
            Equation equation = new Equation().generateSubEquation();
            if(isExist(equation)){
                continue;
            }else{
                equationList.add(equation);
                i++;
            }
        }
    }

    public void generateMixExercise(){
        int i = 0;
        while(i<count){
            Equation equation = new Equation().generateRandomEquation();
            if(isExist(equation)){
                continue;
            }else{
                equationList.add(equation);
                i++;
            }
        }
    }

    public void printExercise(){
        System.out.println("=============");
        System.out.println("小学加减法试题自动生成器");
        System.out.println("=============");
//        for(int i = 0; i < equationList.size(); i++){
//            System.out.println("第" + (i + 1) + "题: " + equationList.get(i).toString());
//        }
        int i = 1;

        int rowCount = 0;
        int equationCount = 0;
        for (Object equation : equationList) {

            System.out.print("第" + i + "题\t" + equation + "\t");
            i++;
            equationCount++;
            if (equationCount % 10 == 0) {
                System.out.println();
                rowCount++;
                if (rowCount == 5) {
                    break;
                }
            }
        }
        if (equationCount % 10 != 0) {
            System.out.println();
        }
    }

    public void printExerciseResult(){
        System.out.println("=============");
        System.out.println("本套试卷参考答案");
        System.out.println("=============");
        int rowCount = 0;
        int equationCount = 0;
        for(int i = 0; i < equationList.size(); i++){

            System.out.print("第" + (i + 1) + "题答案:\t " + equationList.get(i).getResult()+"\t");
            equationCount++;
            if (equationCount % 10 == 0) {
                System.out.println();
                rowCount++;
                if (rowCount == 5) {
                    break;
                }
            }
        }
        if (equationCount % 10 != 0) {
            System.out.println();
        }

        }

}
